<?php
class Forum_Helper_Message
{
    /**
     * Singleton instance
     * @var Forum_Helper_Message
     */
    private static $_instance = null;
    
    /**
     * Retrieve instance of Forum_Helper_Message
     * 
     * @return Forum_Helper_Message
     */
    public static function getInstance()
    {
        if (null === self::$_instance) {
            self::$_instance = new self();
        }
        return self::$_instance;
    }
    
    public function __toString()
    {
        $messages = Forum_Message::getInstance()->get();
        
        $result = "";
        
        if (count($messages)) {
            $result .= "<div id='messages'>";
            foreach ($messages as $type => $messageArray) {
                $result .= "<ul class='{$type}-msg' title='{$type}'>";
                foreach ($messageArray as $message) {
                    $result .= "<li>{$message}</li>";
                }
                $result .= "</ul>";
            }
            $result .= "</div>";
        }
        
        return $result;
    }
}